home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / setkbd22.lzh / setkbd22.lst < prev    next >
File List  |  1990-05-12  |  7KB  |  235 lines

  1. ' Set Clock
  2. ' by Damien M. Jones
  3. ' Copyright © 1990 Damien M. Jones
  4. ' Version 2.2 (Reset-proof)
  5. ' Written for use with TODAY/ST (although can be used by itself)
  6. ' 05/12/90
  7. '
  8. Deffn Bcd(Byte%)=(Byte% Div 10)*16+(Byte% Mod 10)
  9. '
  10. Res%=Xbios(4) ! Current screen resolution
  11. '
  12. @Savecolor ! Save original colors.
  13. If Res%=0 ! Low res, switch to medium.
  14.   Void Xbios(5,L:-1,L:-1,W:1) ! Switch!
  15. Endif
  16. Setcolor 0,7,7,7 ! Background to white. (Standard ST colors)
  17. Setcolor 1,7,0,0 ! Red
  18. Setcolor 2,0,7,0 ! Green.
  19. Setcolor 3,0,0,0 ! Text to black.
  20. '
  21. Dim Data%(2) ! 12 bytes, plenty of space for the clock.
  22. Let Data%=Varptr(Data%(0)) ! Address of it.
  23. '
  24. Print Space$(18);"Set Clock 2.2  by Damien M. Jones  05/12/90" ! Credits!
  25. Print Space$(13);"Copyright © 1990 Damien M. Jones. All Rights Reserved."
  26. Print Space$(27);"This program is Freeware."
  27. Print
  28. '
  29. @Read_clock
  30. @Settime(T$,D$) ! Set it right away.
  31. '
  32. @Set_date ! Get possible new date.
  33. '
  34. @Settime("",D$) ! Set it.
  35. '
  36. @Set_time ! Get possible new time.
  37. '
  38. @Settime(T$,"") ! Set system clock from that data. This also sets the IKBD clock.
  39. '
  40. If Res%=0 ! Started in low res.
  41.   Void Xbios(5,L:-1,L:-1,W:0) ! Switch back
  42.   Void Xbios(6,L:Varptr(Q$)) ! Reset colors (may be necessary)
  43. Endif
  44. '
  45. Edit
  46. '
  47. Procedure Settime(T$,D$) ! This is where the setting is done.
  48.   Poke Data%,27 ! Code for set clock on IKBD
  49.   If D$<>"" ! Date to set
  50.     Poke Data%+1,@Bcd(Val(Right$(D$,2))) ! Year
  51.     Poke Data%+2,@Bcd(Val(Left$(D$,2))) ! Month
  52.     Poke Data%+3,@Bcd(Val(Mid$(D$,4,2))) ! Date
  53.   Else
  54.     Poke Data%+1,255 ! This tells the IKBD not to set this.
  55.     Poke Data%+2,255 ! This tells the IKBD not to set this.
  56.     Poke Data%+3,255 ! This tells the IKBD not to set this.
  57.   Endif
  58.   If T$<>"" ! Time to set
  59.     Poke Data%+4,@Bcd(Val(Left$(T$,2))) ! Hour
  60.     Poke Data%+5,@Bcd(Val(Mid$(T$,4,2))) ! Minutes
  61.     Poke Data%+6,@Bcd(Val(Right$(T$,2))) ! Seconds
  62.   Else
  63.     Poke Data%+4,255 ! This tells the IKBD not to set this.
  64.     Poke Data%+5,255 ! This tells the IKBD not to set this.
  65.     Poke Data%+6,255 ! This tells the IKBD not to set this.
  66.   Endif
  67.   Void Xbios(25,W:7,L:Data%) ! Write all data to IKBD
  68.   Pause 5 ! Short delay.
  69.   Settime T$,D$ ! Set system time and date.
  70. Return
  71. '
  72. Procedure Get_byte ! This is used by Read_clock
  73.   Byte$=""
  74.   If Peek(Data%+Byte%)<16 ! one-digit hex
  75.     Byte$="0"
  76.   Endif
  77.   Byte$=Byte$+Hex$(Peek(Data%+Byte%))
  78.   Inc Byte% ! Next byte.
  79. Return
  80. '
  81. Procedure Savecolor
  82.   Local X%
  83.   Q$=""
  84.   For X%=0 To 15
  85.     Q$=Q$+Mki$(Xbios(7,X%,-1) And &H777)
  86.   Next X%
  87. Return
  88. '
  89. Procedure Read_clock
  90.   Address%=0 ! Place to store the address of the clock packet.
  91.   Machine_code$=Mki$(&H23C8)+Mkl$(*Address%)+Mki$(&H4E75) ! move.l a0,*A%   rts
  92.   Vector%=Xbios(34)+20 ! Old clockvec location
  93.   Old_vector%=Lpeek(Vector%) ! Old clockvec value
  94.   Lpoke Vector%,Varptr(Machine_code$) ! New clock value
  95.   Address%=0 ! Clear value (just to be sure).
  96.   Out 4,&H1C ! Request a clock value
  97.   Repeat     ! Wait for Interrupt
  98.   Until Address%   ! (Until an address is present in A%
  99.   Bmove Address%,Data%,6 ! Move it before it gets overwritten
  100.   Lpoke Vector%,Old_vector% ! Restore old vector
  101.   '
  102.   D$="" ! Place to store date.
  103.   T$="" ! Place to store time, also a temporary string.
  104.   Byte%=0 ! Starting at byte 0.
  105.   @Get_byte ! Read year.
  106.   D$="/"+Byte$
  107.   @Get_byte ! Read date.
  108.   T$=Byte$+"/"
  109.   @Get_byte
  110.   D$=T$+Byte$+D$ ! Month, date, and year.
  111.   T$="" ! Clear it again.
  112.   @Get_byte ! Read hours.
  113.   T$=Byte$+":"
  114.   @Get_byte ! Read minutes.
  115.   T$=T$+Byte$+":"
  116.   @Get_byte ! Read seconds.
  117.   T$=T$+Byte$
  118. Return
  119. '
  120. Procedure Set_time
  121.   Local I$,I%,Tim$,First!,Tim%
  122.   Tim%=Timer ! Time routine was entered
  123.   I$=T$  ! current time
  124.   Tim$=I$   ! save that time, if they match, the time is NOT set
  125.   Print Space$(31);"Set time:         ";
  126.   First!=-1 ! First time through
  127.   Repeat
  128.     Print "f";Left$("✓✓✓✓✓✓✓✓",Len(I$));I$;"        ✓✓✓✓✓✓✓✓";"e";
  129.     While (Not Inp?(2)) And First!=-1 ! Only update the first time.
  130.       @Read_clock ! Update clock.
  131.       If Timer-Tim%>800 ! More than four seconds have passed
  132.         Time_out!=-1 ! Time out
  133.       Endif
  134.       Exit If Time_out! ! Time to exit loop
  135.       If T$<>I$ ! Changed.
  136.         Print "f✓✓✓✓✓✓✓✓";T$;"e";
  137.         I$=T$
  138.       Endif
  139.     Wend
  140.     Exit If Time_out! ! Time to exit
  141.     I%=Inp(2) ! keyboard input
  142.     If I%<>8 And I%<>13 And First!=-1 ! First time through, not a RETURN or BACKSPACE
  143.       I$="" ! Clear input string
  144.       Print "f✓✓✓✓✓✓✓✓        ✓✓✓✓✓✓✓✓e"; ! Cursor off, back up, erase, back up, cursor on
  145.     Endif
  146.     First!=0 ! No longer the first time.
  147.     If I%>47 And I%<58 And Len(I$)<8 ! digit, 0-9, room for it too
  148.       I$=I$+Chr$(I%)
  149.       Print Chr$(I%);
  150.       If Len(I$)=2 Or Len(I$)=5
  151.         Print ":";
  152.         I$=I$+":" ! add a colon
  153.       Endif
  154.     Else
  155.       If I%=8 And I$<>"" ! backspace
  156.         Print "✓";
  157.         If Right$(I$)=":" ! colon is the last character
  158.           Print "✓";
  159.           I$=Left$(I$,Len(I$)-1) ! backspace the colon
  160.         Endif
  161.         I$=Left$(I$,Len(I$)-1) ! backspace last number
  162.       Else
  163.         If I%=27 ! ESC
  164.           Print Left$("✓✓✓✓✓✓✓✓",Len(I$));
  165.           I$="" ! Clear
  166.         Endif
  167.       Endif
  168.     Endif
  169.   Until I%=13
  170.   If I$<>Tim$ ! new time was entered
  171.     T$=I$ ! Set it on return
  172.   Else
  173.     T$="" ! Don't set it.
  174.   Endif
  175.   Print "f" ! Cursor off.
  176. Return
  177. '
  178. Procedure Set_date
  179.   Local I$,I%,Tim$,First!,Tim%
  180.   Tim%=Timer ! Time routine was entered
  181.   I$=D$  ! current time
  182.   Tim$=I$   ! save that time, if they match, the time is NOT set
  183.   Print Space$(31);"Set Date:         ";
  184.   First!=-1 ! First time through
  185.   Repeat
  186.     Print "f";Left$("✓✓✓✓✓✓✓✓",Len(I$));I$;"        ✓✓✓✓✓✓✓✓";"e";
  187.     While (Not Inp?(2)) And First!=-1 ! Only update the first time.
  188.       @Read_clock ! Update clock.
  189.       If Timer-Tim%>800 ! More than four seconds have passed
  190.         Time_out!=-1 ! Time out
  191.       Endif
  192.       Exit If Time_out! ! Time to exit loop
  193.       If D$<>I$
  194.         Print "f✓✓✓✓✓✓✓✓";D$;"e";
  195.         I$=D$
  196.       Endif
  197.     Wend
  198.     Exit If Time_out! ! Time to exit
  199.     I%=Inp(2) ! keyboard input
  200.     If I%<>8 And I%<>13 And First!=-1 ! First time through, not a RETURN or BACKSPACE
  201.       I$="" ! Clear input string
  202.       Print "f✓✓✓✓✓✓✓✓        ✓✓✓✓✓✓✓✓e"; ! Cursor off, back up, erase, back up, cursor on
  203.     Endif
  204.     First!=0 ! No longer the first time.
  205.     If I%>47 And I%<58 And Len(I$)<8 ! digit, 0-9, room for it too
  206.       I$=I$+Chr$(I%)
  207.       Print Chr$(I%);
  208.       If Len(I$)=2 Or Len(I$)=5
  209.         Print "/";
  210.         I$=I$+"/" ! add a slash
  211.       Endif
  212.     Else
  213.       If I%=8 And I$<>"" ! backspace
  214.         Print "✓";
  215.         If Right$(I$)="/" ! slash is the last character
  216.           Print "✓";
  217.           I$=Left$(I$,Len(I$)-1) ! backspace the slash
  218.         Endif
  219.         I$=Left$(I$,Len(I$)-1) ! backspace last number
  220.       Else
  221.         If I%=27 ! ESC
  222.           Print Left$("✓✓✓✓✓✓✓✓",Len(I$));
  223.           I$="" ! Clear
  224.         Endif
  225.       Endif
  226.     Endif
  227.   Until I%=13
  228.   If I$<>Tim$ ! new date was entered
  229.     D$=I$ ! Set it on return
  230.   Else
  231.     D$="" ! Don't set it.
  232.   Endif
  233.   Print "f" ! Cursor off.
  234. Return
  235.